package com.gpzx.zx.module.home.frame.view

import android.content.Context
import android.graphics.Color
import com.gpzx.zx.module.home.ui.adapter.NewHomePagerAdapter
import com.gpzx.zx.module.home.ui.fragment.NewHomeFragment
import com.gpzx.zx.module.mine.ui.activity.CalendarActivity
import com.wkq.base.frame.mosby.delegate.MvpView
import com.wu.common.module.ui.widget.ScaleTransitionPagerTitleView
import net.lucode.hackware.magicindicator.ViewPagerHelper
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.BezierPagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView

/**
 *
 * 作者:吴奎庆
 *
 * 时间:2020/7/16
 *
 * 用途:
 */


class NewHomeView : MvpView {
    var titleList= listOf<String>("最新")
    var mFragment: NewHomeFragment

    constructor(fragment: NewHomeFragment) {
        mFragment = fragment
    }

    fun initView() {
       var adapter= NewHomePagerAdapter(mFragment.context,mFragment.childFragmentManager)
        mFragment.binding.vpContent.adapter=adapter
        val magicIndicator = mFragment.binding.magicIndicator
        magicIndicator.setBackgroundColor(Color.WHITE)
        val commonNavigator = CommonNavigator(mFragment.activity)
        commonNavigator.adapter = object : CommonNavigatorAdapter() {
            override fun getCount(): Int {
                return if (titleList == null) 0 else titleList.size
            }

            override fun getTitleView(context: Context, index: Int): IPagerTitleView {
                val simplePagerTitleView: SimplePagerTitleView = ScaleTransitionPagerTitleView(context)
                simplePagerTitleView.setText(titleList.get(index))
                simplePagerTitleView.textSize = 18f
                simplePagerTitleView.normalColor = Color.GRAY
                simplePagerTitleView.selectedColor = Color.BLACK
                simplePagerTitleView.setOnClickListener { mFragment.binding.vpContent.setCurrentItem(index) }
                return simplePagerTitleView
            }

            override fun getIndicator(context: Context): IPagerIndicator {
                val indicator = BezierPagerIndicator(context)
                indicator.setColors(Color.parseColor("#ff4a42"), Color.parseColor("#fcde64"), Color.parseColor("#73e8f4"), Color.parseColor("#76b0ff"), Color.parseColor("#c683fe"))
                return indicator
            }
        }

        magicIndicator.navigator = commonNavigator
        ViewPagerHelper.bind(magicIndicator, mFragment.binding.vpContent)

        mFragment.binding.ivAd.setOnClickListener { CalendarActivity.newInstance(mFragment.activity as Context) }

    }
}